#!/bin/bash
##Linux测试脚本集合主脚本
#Update_Time:2020年09月27日_23:19:36
export install_config="/install_config.sh"
export test_config="/test_config.sh"
cmd(){
    mkdir -p /log/
    d=`date`
    $1
    if [[ "$?" -eq "0" ]];then
        echo -e "执行的命令:[$1]\t执行时间[${d}]\t结束时间[`date`]\t执行结果[成功]\n" | tee -a /log/Run.log
    else
        echo -e "执行的命令:[$1]\t执行时间[${d}]\t结束时间[`date`]\t执行结果[失败]\n"  | tee -a /log/Run.log
    fi
}
chek_file(){
    dir=`pwd`
    f='/item.sh /installer.sh /Test_script.sh'
    for i in $f;do
        if [[ -e "${dir}${i}" ]];then
            cmd "source ${dir}${i}"
        else
            echo "找不到脚本文件[$i]"
            return "1"
        fi
    done
}
chek_file
# ######################测试项定义区
# # if [[ "$USER" -eq "root" ]];then
# #     print_green_zt "当前用户权限正确"
# # else
# #     print_red_z_z_bg "请切换至" "[root]用户"
# #     exit 1
# # fi
# USER_CHECK
# config_check(){
# 	if [[  -z "$1" ]];then
# 		print_red_z_z_bg "${2}" "未设置\n"
# 		set_not="$set_not $2"  
# 	else
# 		print_red_z_green_z_info "${2}" "已设置\n"
# 		set="$set $2"
# 	fi
# }
# # source $test_config $install_config
# # config_check "$JAVA_HOME" "JAVA_HOME"
# # config_check "$UnixBench_ZIP" "UnixBench安装"
# # config_check "$iozone_ZIP" "iozone安装"
# # config_check "$netperf_ZIP" "netperf安装"
# # config_check "$SPECJVM_ZIP" "SPECJVM安装"

# # config_check "$UnixBench_DIR" "UnixBench测试"
# # config_check "$iozone_DIR" "iozone_DIR测试"
# # config_check "$netperf_SERVER" "netperf服务器参数"
# # config_check "$SPECJVM_INSTALLER" "SPECJVM安装"



# performance(){
# 	input '请选择需要使用的测试工具
# [1]LMBench
# [2]UnixBench
# [3]netperf
# [4]SPECjvm2008
# [5]stream
# [6]iozone
# [7]磁盘文件创建测试
# [8]USB读写测试' type
# 	expr $type "+" 10 >> /dev/null
# 	if [[ $? -eq '0' ]];then
# 		case "$type" in
# 			"1") LMBench_test 
# 			;;
# 			"2") Unixbench_test
# 			;;
# 			"3") netperf_test
# 			;;
# 			"4") SPECjvm_test
# 			;;
#             "5") stream_test
#             ;;
#             "6") iozone_Test
#             ;;
#             "7") echo 'd'
#             ;;
#             "8") USB_storage
#             ;;
# 		esac
# 	else
# 		if [[ "$type" == "A" || "$type" == 'a' ]];then
# 			echo 'use all'
# 		else
# 			echo 'select errors'
# 		fi
# 	fi
# }

# #系统信息检测
# os_ver(){
# 	echo -e "正在检测系统信息\n正在检测系统架构"
# 	Framework=`uname -m`
# 	echo '正在检测包类型'
# 	if [[  -f "/usr/bin/yum" ]];then
# 		package='rpm'
# 	elif [[ -f "/usr/bin/apt" ]];then
# 		package='deb'
# 	elif [[ -f "/usr/bin/apt-get" ]];then
# 		package='deb'
# 	else
# 		echo -e "无法判断该系统使用的包,请选择
# [1]rpm
# [2]deb"
# 		read p
# 		if [[ "$p" == "1" ]];then
# 			package='rpm'
# 		elif [[  "$p" == "2" ]];then
# 			package='deb'
# 		else
# 			echo '选择错误'
# 			exit 1
# 		fi
# 	fi
# 	echo '正在检测发行版'
# 	ver=`cat /etc/os-release | grep 'PRETTY_NAME' | sed 's/PRETTY_NAME="//'| awk '{print $1}'`
# 	echo -e "本机系统架构:	\033[31m${Framework}\033[0m
# 使用的默认包类型:	\033[35m${package}\033[0m
# 当前Linux发行版:	\033[35m${ver}\033[0m
# 其他:	待更新"
# 	echo -e "\033[5;35m确认无误请回车\033[0m"
# 	read dd
# }
# ##如果检测到有传参，则判断传入的参数为需要执行的函数
# if [[ "$1" -eq "-h" || "$1" -eq "--help" || "$1" -eq "help" || "$1" -eq "?" ]];then
#     print_green_zt "可通过传参快速进入一个测试例,语法如下："
#     print_red_z_green_z "语法命令:\t" "bash spzx_Test.sh -f '$函数'\n"

#     print_green_zt "函数功能对照表如下"
#     print_red_z_green_z "文件创建测试" "[create_file]" 
#     print_red_z_green_z "USB读写测试" "[USB_storage]" 
#     print_red_z_green_z "CPU线程测试" "[stream_test]" 
#     print_red_z_green_z "JAVA虚拟性能测试" "[SPECjvm_test]"
#     print_red_z_green_z "磁盘读写测试" "[iozone_Test]"
#     print_red_z_green_z "Unixbench性能测试" "[Unixbench_test]"
#     print_red_z_green_z "LMBench性能测试" "[LMBench_test]"
#     print_red_z_green_z "示例(命令取[]包含的内容，不包含[]本身):\t" "[bash spzx_Test.sh -f 'create_file']"
#     print_red_z_green_z "同时支持多个函数一次传入,例如:\t" "[bash spzx_Test.sh -f 'create_file iozone_Test Unixbench_test']"
# elif [[ "$1" -eq "-f" ]];then
#     for i in $*;do
#         if [[ "$i" -eq "-f" ]];then
#             print_green_zt "跳过"
#         else
#             $i
#         fi
#     done
# fi

# #检测配置文件
# if [[  ! -f "$install_config" ]];then
# 	print_red_z_z_bg "请先配置:" "\nvim $install_config"

# else
#     if [[ ! -f "$test_config" ]];then
#         	print_red_z_z_bg "请先配置:" "\nvim $test_config"

#     else
#         if [[ "$Config_check" -eq 'y' ]];then
#             echo '继续'
#         else
#             print_red_z_z_bg "请先配置:" "\nvim $test_config"
#         fi
#     fi
#     if [[ "$installer_config" -eq 'y' ]];then
#             echo '继续'
#     else
#             print_red_z_z_bg "请先配置:" "\nvim $test_config"
#     fi
# fi
# ###文件夹预创建
# # mkdir -p $LOG_DIR $INS_DIR
# os_ver
# performance
# ##脚本第一运行块
